﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using POSSystem.BLL;

namespace WebUI.Controls
{
    public partial class LoanPhoneListCtrl : BaseListControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
        }

        public void DeleteCheckedItems()
        {
            try
            {
                String checkedItemID = "";
                for (int i = 0; i < grid.Items.Count; i++)
                {
                    DataGridItem item = grid.Items[i];
                    Control ctrl = item.FindControl("cbSelect");
                    if (ctrl != null && ctrl is CheckBox && ((CheckBox)ctrl).Checked && ((CheckBox)ctrl).Attributes["ItemID"] != null)
                        checkedItemID += ((CheckBox)ctrl).Attributes["ItemID"].ToString() + ",";
                }
                if (checkedItemID != "")
                    checkedItemID = checkedItemID.Remove(checkedItemID.Length - 1);
                if (checkedItemID != "")
                    LoanPhones.DeleteLoanPhones(checkedItemID);
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("LoanPhoneListCtrl.ascx.cs", "DeleteCheckedItems", ex.Message + "\r\n" + ex.StackTrace);
                throw ex;
            }
        }
    }
}